package cn.wolfcode.demo;


import org.activiti.engine.*;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.junit.Test;

public class demo5 {
    @Test
    public void testDemo(){
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        System.out.println(processEngine);
    }
    @Test
    public void testDeploy(){
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        RepositoryService repositoryService = processEngine.getRepositoryService();
        Deployment deployment = repositoryService.createDeployment().addClasspathResource("bpnm/leave-candidate.bpmn")
                .addClasspathResource("bpnm/leave-candidate.png")
                .name("候选人").deploy();
        System.out.println(deployment.getId() + "流程部署ID");
        System.out.println("流程部署名称" + deployment.getName());
    }
    @Test
    public void testStartProcess(){
        //创建ProcessEngine对象
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        //获取RuntimeService对象
        RuntimeService runtimeService = processEngine.getRuntimeService();
        //根据流程定义的key启动流程实例,这个key是在定义bpmn的时候设置的
        ProcessInstance instance = runtimeService.startProcessInstanceByKey("leave-candidate");
        //获取流程实例的相关信息
        System.out.println("流程定义的id = " + instance.getProcessDefinitionId());
        System.out.println("流程实例的id = " + instance.getId());
    }
@Test
public void testClaimTask(){
 String taskId="2505";
    //创建ProcessEngine对象
    ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
    TaskService taskService = processEngine.getTaskService();
    taskService.claim(taskId,"lisi");
}
@Test
    public void testCompleteTask(){
        String taskId="2505";
    ProcessEngine processEngines = ProcessEngines.getDefaultProcessEngine();
    TaskService taskService = processEngines.getTaskService();
    taskService.complete(taskId);
}
}
